package krow.dev.contest.view;

import java.util.List;

import krow.dev.contest.Constants.Invoke;
import krow.dev.contest.SubcategoryFragment;
import krow.dev.contest.model.TabItem;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;


public class CategoryPageAdapter extends FragmentPagerAdapter {

	private List<TabItem> mTabItemList;
	
	public CategoryPageAdapter(FragmentManager fragmentManager, List<TabItem> tabItemList) {
		super(fragmentManager);
		
		mTabItemList = tabItemList;
	}
	
	@Override
	public CharSequence getPageTitle(int position) {
		
		return mTabItemList.get(position).getName();
	}

	@Override
	public int getCount() {
		
		return mTabItemList.size();
	}

	@Override
	public Fragment getItem(int position) {
		
		TabItem tabItem = mTabItemList.get(position);
		
		Bundle arguments = new Bundle();
		arguments.putString(Invoke.KEY_CATEGORY, tabItem.getCategory());
		
		SubcategoryFragment subCategoryFragment = new SubcategoryFragment();
		subCategoryFragment.setArguments(arguments);
		
		return subCategoryFragment;
	}

}
